#include "taskQueue.h"

int initQueue(taskQueue_t *pQueue){
    bzero(pQueue,sizeof(taskQueue_t));
    return 0;
}

int enQueue(taskQueue_t *pQueue,server_t *pserver){
    task_t *pNew = (task_t *)calloc(1,sizeof(task_t));
    /* pNew->pserver = pserver; */
    pNew->pserver = (server_t *)malloc(sizeof(server_t));
    memcpy(pNew->pserver, pserver, sizeof(server_t));
    if(pQueue->queueSize == 0){
        pQueue->pFront = pNew;
        pQueue->pRear = pNew;
    }
    else{
        pQueue->pRear->pNext = pNew;
        pQueue->pRear = pNew;
    }
    ++pQueue->queueSize;
    return 0;
}

int deQueue(taskQueue_t *pQueue){
    task_t *pCur = pQueue->pFront;
    pQueue->pFront = pCur->pNext;
    if(pQueue->queueSize == 1){
        pQueue->pRear = NULL;
    }
    free(pCur->pserver);  // 释放server_t结构体
    free(pCur);
    --pQueue->queueSize;
    return 0;
}

